package com.chenjian.annotation.service.impl;

import com.chenjian.annotation.custom.anno.CustomAutowired;
import com.chenjian.annotation.custom.anno.CustomService;
import com.chenjian.annotation.custom.anno.CustomTransactional;
import com.chenjian.annotation.dao.JdbcAccountDaoImpl;
import com.chenjian.annotation.pojo.Account;
import com.chenjian.annotation.service.ZhuanZzhangService;

@CustomService
@CustomTransactional
public class ZhuanZhangServiceImpl implements ZhuanZzhangService {

    @CustomAutowired
    private JdbcAccountDaoImpl jdbcAccountDao;


    @Override
    public void transfer(String fromCardNo, String toCardNo, int money) throws Exception {
        Account from = jdbcAccountDao.queryAccountByCardNo(fromCardNo);
        Account to = jdbcAccountDao.queryAccountByCardNo(toCardNo);

        from.setMoney(from.getMoney() - money);
        to.setMoney(to.getMoney() + money);

        jdbcAccountDao.updateAccountByCardNo(to);
        //手动除0异常
        int c = 1/0;
        jdbcAccountDao.updateAccountByCardNo(from);
    }
}
